-
Notifications
You must be signed in to change notification settings - Fork 409
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Removed transaction from segment. Introduced a new enterSegment and enterTransaction to make context propagation more clear #2646
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## next #2646 +/- ##
=======================================
Coverage ? 97.25%
=======================================
Files ? 291
Lines ? 46251
Branches ? 0
=======================================
Hits ? 44981
Misses ? 1270
Partials ? 0
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
a876112
to
94f381a
Compare
94f381a
to
3cd3159
Compare
cb93d08
to
c2afb3f
Compare
c2afb3f
to
b7b4ef8
Compare
enterTransaction
b7b4ef8
to
17ea0db
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As expected, most of the changes are signature related updates. The majority of my comments are around making sure our inline docs are correct. But I do have a couple of clarifying questions.
lib/agent.js
Outdated
@@ -843,7 +842,7 @@ Agent.prototype.getLinkingMetadata = function getLinkingMetadata() { | |||
} | |||
|
|||
if (config.distributed_tracing.enabled && segment) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like the only usage of segment
in this function, and it was previously used only to get the transaction. I think we can remove const segment = this.tracer.getSegment()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the line right below it is using segment to get the span id
@@ -21,10 +21,9 @@ function ParsedStatement(type, operation, collection, raw) { | |||
} | |||
} | |||
|
|||
ParsedStatement.prototype.recordMetrics = function recordMetrics(segment, scope) { | |||
ParsedStatement.prototype.recordMetrics = function recordMetrics(segment, scope, transaction) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think we will eventually remove segment
from the parameters and then retrieve it from the transaction in the function body?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand. Recorders are registered at the start of recording of a segment. In tracer they are added to transaction and binding the appropriate segment:
if (recorder) {
transaction.addRecorder(recorder.bind(null, segment))
}
Then once a transaction end it iterates over all the recorders and calls the function with the scope and the transaction
Transaction.prototype.record = function record() {
const name = this.name
for (let i = 0, l = this._recorders.length; i < l; ++i) {
this._recorders[i](name, this)
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't this work make transaction
the entry point of the API? As in, wouldn't we attempt to retrieve a segment from the transaction?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect all of the functions that are getting a new transaction
parameter can also drop the segment
parameter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need the segment because it's getting ended
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed all comments and responded to questions in here
@@ -15,7 +15,7 @@ const repos = [ | |||
{ | |||
name: 'apollo-server', | |||
repository: 'https://github.com/newrelic/newrelic-node-apollo-server-plugin.git', | |||
branch: 'main', | |||
branch: 'remove-transaction-from-segment', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so I had to update this repo too. we're going to have to keep track of this when we release
lib/agent.js
Outdated
@@ -843,7 +842,7 @@ Agent.prototype.getLinkingMetadata = function getLinkingMetadata() { | |||
} | |||
|
|||
if (config.distributed_tracing.enabled && segment) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the line right below it is using segment to get the span id
@@ -21,10 +21,9 @@ function ParsedStatement(type, operation, collection, raw) { | |||
} | |||
} | |||
|
|||
ParsedStatement.prototype.recordMetrics = function recordMetrics(segment, scope) { | |||
ParsedStatement.prototype.recordMetrics = function recordMetrics(segment, scope, transaction) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand. Recorders are registered at the start of recording of a segment. In tracer they are added to transaction and binding the appropriate segment:
if (recorder) {
transaction.addRecorder(recorder.bind(null, segment))
}
Then once a transaction end it iterates over all the recorders and calls the function with the scope and the transaction
Transaction.prototype.record = function record() {
const name = this.name
for (let i = 0, l = this._recorders.length; i < l; ++i) {
this._recorders[i](name, this)
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need the segment because it's getting ended
lib/transaction/index.js
Outdated
@@ -22,6 +22,7 @@ const Logs = require('./logs') | |||
const DT_ACCEPT_PAYLOAD_EXCEPTION_METRIC = 'DistributedTrace/AcceptPayload/Exception' | |||
const DT_ACCEPT_PAYLOAD_PARSE_EXCEPTION_METRIC = 'DistributedTrace/AcceptPayload/ParseException' | |||
const REQUEST_PARAMS_PATH = 'request.parameters.' | |||
const TraceStacks = require('../util/trace-stacks') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'm going to remove this trace stacks idea. it's a debug thing that seems useless
lib/transaction/tracer/index.js
Outdated
wrapped[symbols.original] = getOriginal(handler) | ||
wrapped[symbols.segment] = active | ||
// wrapped[symbols.segment] = segment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll restore this but not sure if we need it
… and enterTransaction to make context propagation more clear (#2646)
Closes #2658 |
… and enterTransaction to make context propagation more clear (#2646)
… and enterTransaction to make context propagation more clear (#2646)
… and enterTransaction to make context propagation more clear (#2646)
… and enterTransaction to make context propagation more clear (#2646)
… and enterTransaction to make context propagation more clear (#2646)
… and enterTransaction to make context propagation more clear (#2646)
… and enterTransaction to make context propagation more clear (#2646)
… and enterTransaction to make context propagation more clear (#2646)
… and enterTransaction to make context propagation more clear (newrelic#2646)
… and enterTransaction to make context propagation more clear (#2646)
… and enterTransaction to make context propagation more clear (#2646)
… and enterTransaction to make context propagation more clear (#2646)
… and enterTransaction to make context propagation more clear (#2646)
… and enterTransaction to make context propagation more clear (#2646)
This change introduced a breaking change that broke @newrelic/apollo-server-plugin
I just filed an issue: #2903 |
This PR is a lot so I apologize. This removes transaction from segment, introduces a context class for storing the active transaction and segment as well as helpers to create a new context for entering a new segment and transaction.
Note: You will see two instances where
enterSegment
passes in the transaction because the 3rd party promise intrumentation has its own context manager. Some follow up work will occur in #2657. This is targetingnext
as this is quite a radical change and we need to do more manual testing once all the work is done